function img = cube2RGB(cube,bands,white_balance)
    % cube2RGB.m 函数基于a.mat，合成RGB图像，这两个参数需分别运行
    % 
    % 需设置参数：① 棋盘格全幅待几何与透过率校正光谱图片的文件夹路径ImageFolder
    % 
    % 返回：① 返回向基准波长校准的RGB的图片img    
    
    FileNum = size(cube,3);
    WaveLength = bands;
    cube = cube/max(cube,[],'all');
    I = squeeze(cube(:,:,1));
    shape = size(I);
    R = double(zeros(shape));
    G = double(zeros(shape));
    B = double(zeros(shape));
    for i = 1:FileNum
        J = squeeze(cube(:,:,i));
        [r,g,b]=spec2RGB(WaveLength(i),white_balance);
        R = R + r*J;
        G = G + g*J;
        B = B + b*J;
    end
    R = (R./FileNum);
    G = (G./FileNum);
    B = (B./FileNum);
    img = cat(3,R,G,B);
end